/** 题目根据题型排序 **/

function getQuestionTypeMap() {

    return {
        "选择题": "选择题",
        "单选题": "选择题",
        "多选题": "选择题",
        "不定项选择题":"选择题",
        "判断题": "判断题",
        "填空题": "填空题",
    }
}

function getQuestionType(questionType){
    let questionTypeMap = getQuestionTypeMap();
    return questionTypeMap[questionType] ? questionTypeMap[questionType] : questionType;
}

function getQuestionOrderMap() {

    return {
      "现代文阅读": [],
      "文言文阅读": [],
      "诗歌鉴赏": [],
      "默写": [],
      "选择题": [],
      "单选题":[],
      "不定项选择题":[],
      "语言表达": [],
      "名著导读": [],

      "填空题": [],
      "问答题": [],
      "简答题": [],
      "推断题": [],
      "实验题": [],
      "计算题": [],
    };
}

function sortQuestion(questions) {

    let questionOrderMap = getQuestionOrderMap();

    questions.forEach(question => {

        let questionType = getQuestionType(question.questionType);
        if (!questionOrderMap[questionType]) {
            questionOrderMap[questionType] = [];
        }
        questionOrderMap[questionType].push(question);
    });

    return questionOrderMap;
}

function sortQuestionType(typeList){

    let questionOrderMap = getQuestionOrderMap();
    let newTypeList = [];
    let typeArray = Object.keys(questionOrderMap);
    typeList.forEach((type)=>{
        let tag = 0, hasGet =false;
        typeArray.forEach((sortOrder)=>{
            if(hasGet)return;
            if(sortOrder === type){
                hasGet = true;
                newTypeList.push({type,val:tag});
                return;
            }else{
                tag++;
            }
            if((tag+1)===typeArray.length){
                hasGet = true;
                newTypeList.push({type,val:tag});
            }
        });
    });
    return newTypeList.sort((a,b)=>{return a.val-b.val}).map((value, index, arr)=>arr[index]=value.type)
}


export {getQuestionTypeMap, getQuestionOrderMap, sortQuestion,getQuestionType,sortQuestionType}
